﻿using Architecture.API.Application.Command.RequestForLeaveCommand;
using Architecture.Domain.Service.LeaveServices;
using MediatR;

namespace Architecture.API.Application.CommandHandlers.RequestForLeaveHandler
{
    /// <summary>
    /// 删除请假命令创建
    /// </summary>
    public class DeletedLeaveCommandHandler : IRequestHandler<DeletedLeaveCommand, int>
    {
        /// <summary>
        /// 请假服务
        /// </summary>
        protected readonly ILeaveService _leaveService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="leaveService">请假服务</param>
        public DeletedLeaveCommandHandler(ILeaveService leaveService)
        {
            _leaveService = leaveService;
        }

        /// <summary>
        /// 删除请假信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(DeletedLeaveCommand request, CancellationToken cancellationToken)
        {
            return await _leaveService.DeletedLeave(request.leaveId);
        }
    }
}
